/*
 * Copyright 2025 arisgo@163.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.arisgo.cloud.auth.sys.api;

import com.arisgo.cloud.common.Result;
import com.arisgo.cloud.web.param.Search;
import com.arisgo.cloud.web.param.Paging;
import com.arisgo.cloud.common.Pagination;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.arisgo.cloud.auth.sys.vo.ParamVo;
import com.arisgo.cloud.auth.sys.service.ParamService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.util.List;

/**
 * 参数表 Api
 *
 * @author Arisgo
 * @since 2024-06-14
 */
@RestController
@AllArgsConstructor
@RequestMapping("/param")
@Tag(name = "参数表 API", description = "参数表CRUD操作")
public class ParamApi {

    private final ParamService paramService;

    /**
     * 依id查询参数表
     */
    @GetMapping(value = "/{id}")
    @Operation(summary = "依id查询")
    public Result<ParamVo> findById(@PathVariable(value = "id") Long id) {
        return Result.success(paramService.findById(id));
    }

    /**
     * 分页查询参数表
     */
    @PostMapping(value = "/page")
    @Operation(summary = "分页查询")
    public Result<Pagination<ParamVo>> page(@RequestBody Paging params) {
        return Result.success(paramService.page(params));
    }

    /**
     * 条件查询参数表
     */
    @PostMapping(value = "/find")
    @Operation(summary = "条件查询")
    public Result<List<ParamVo>> find(@RequestBody Search param) {
        return Result.success(paramService.findByParams(param));
    }

    /**
     * 保存参数表
     */
    @PostMapping
    @Operation(summary = "新增数据")
    public Result<ParamVo> save(@RequestBody ParamVo vo) {
        return Result.success(paramService.save(vo));
    }

    /**
     * 更新参数表
     */
    @PutMapping(value = "/{id}")
    @Operation(summary = "更新数据")
    public Result<Boolean> update(@PathVariable(value = "id") Long id, @RequestBody ParamVo vo) {
        vo.setId(id);
        return Result.success(paramService.update(vo));
    }

    /**
     * 逻辑删除参数表
     */
    @DeleteMapping(value = "/{id}")
    @Operation(summary = "单个逻辑删除")
    public Result<Boolean> delete(@PathVariable(value = "id") Long id) {
        return Result.success(paramService.delete(id));
    }

    /**
     * 逻辑删除参数表
     */
    @DeleteMapping
    @Operation(summary = "批量逻辑删除")
    public Result<Boolean> delete(@RequestBody List<Long> ids) {
        return Result.success(paramService.delete(ids));
    }

    /**
      * 物理删除参数表
      */
    @DeleteMapping(value = "/remove/{id}")
    @Operation(summary = "单个物理删除")
    public Result<Boolean> remove(@PathVariable(value = "id") Long id) {
        return Result.success(paramService.remove(id));
    }

    /**
     * 物理删除参数表
     */
    @DeleteMapping(value = "/remove")
    @Operation(summary = "批量物理删除")
    public Result<Boolean> remove(@RequestBody List<Long> ids) {
        return Result.success(paramService.remove(ids));
    }

}
